#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
    ll xx=0;short flag=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')flag=-1;
        ch=getchar();
    }
    while('0'<=ch&&ch<='9'){
        xx=(xx<<3)+(xx<<1)+ch-'0';
        ch=getchar();
    }
    return xx*flag;
}
int n,T,ans;
multiset<ll> s;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T--){
        n=read(),ans=0;int cnt=-1;
        s.clear();
        for(int i=1;i<=n;i++)s.insert(read());
        for(auto i:s){
            if(i==cnt) continue;
            ans+=(s.count(i)-1)*(i);
            cnt=i;
        }
        cout<<ans<<endl;
    }
    
    
    return 0;
}